package com.yunshang.shoppingmall.common;

import java.util.Random;

public class RandomCodeUtil {
	
	public static String code6Create(){
		double db=(Math.random()*9+1)*100000;
		return String.valueOf(db).substring(0,6);
	}

	//生成随机数字和字母,
	public static String getStringRandom(int length) {

		String val = "";
		Random random = new Random();
		//length为几位密码
		for(int i = 0; i < length; i++) {
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			//输出字母还是数字
			if( "char".equalsIgnoreCase(charOrNum) ) {
				//输出是大写字母还是小写字母
				int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char)(random.nextInt(26) + temp);
			} else if( "num".equalsIgnoreCase(charOrNum) ) {
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val.toLowerCase();
	}

}
